#!/bin/sh
# 安装PHP Memcached扩展
App=memcached
AppName="PHP Memcached扩展"
AppBase=/App
AppSrcFile=$App-*.tgz
AppSrcBase=/App/src
AppSrcDir=$(find $AppSrcBase -maxdepth 1 -name "$AppSrcFile" -type f | sed -e 's/.tgz$//' -e 's/^.\///')

export PATH=/App/php/bin:$PATH
ExtensionDir=$(php-config --extension-dir)

# 安装
finstall() 
{
    ls $ExtensionDir/$App.so &> /dev/null && echo "$AppName 已安装" || fupdate
}

# 更新
fupdate() 
{
    ldconfig
    cd $AppSrcBase
    test -d $AppSrcDir && rm -rf $AppSrcDir

    tar zxf $AppSrcFile
    cd $AppSrcDir
    phpize && ./configure && make && make install

    [ $? -eq 0 ] && echo "$AppName 安装成功" || echo "$AppName 安装失败"
}

ScriptFile=$(basename $0)
case "$1" in
    "install") finstall;;
    "update" ) fupdate;;
    * )
    echo "用法: $ScriptFile {install|update}"
    ;;
esac
